<?php

/**
 * This is the model class for table "sys_member_testimony".
 *
 * The followings are the available columns in table 'sys_member_testimony':
 * @property string $member_testimony_id
 * @property string $member_testimony_network_id
 * @property string $member_testimony_content
 * @property string $member_testimony_input_datetime
 * @property string $member_testimony_is_approve
 * @property string $member_testimony_order_by
 * @property string $member_testimony_home_is_active
 * @property string $member_testimony_home_order_by
 *
 * The followings are the available model relations:
 * @property SysNetwork $memberTestimonyNetwork
 */
class sys_member_testimony extends CActiveRecord {
    
    public $network_mid;

    /**
     * Returns the static model of the specified AR class.
     * @return sys_member_testimony the static model class
     */
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'sys_member_testimony';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('member_testimony_network_id, member_testimony_order_by', 'length', 'max' => 10),
            array('member_testimony_is_approve, member_testimony_home_is_active', 'length', 'max' => 1),
            array('member_testimony_content, member_testimony_input_datetime', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('network_mid, member_testimony_id, member_testimony_network_id, member_testimony_content, member_testimony_input_datetime, member_testimony_is_approve, member_testimony_order_by, member_testimony_home_is_active', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'rel_member_testimony_to_network' => array(self::BELONGS_TO, 'sys_network', 'member_testimony_network_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'member_testimony_id' => 'Testimony',
            'member_testimony_network_id' => 'Member ID',
            'member_testimony_content' => 'Content',
            'member_testimony_input_datetime' => 'Input Datetime',
            'member_testimony_is_approve' => 'Publish',
            'member_testimony_order_by' => 'Order By',
            'member_testimony_home_is_active' => 'Home Is Active',
            'network_mid' => 'Member ID',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;
        
        $criteria->select = "t.*, sys_network.network_mid AS network_mid
            ";
        
        $criteria->join = "LEFT JOIN sys_network 
            ON member_testimony_network_id = sys_network.network_id";

        $criteria->compare('member_testimony_id', $this->member_testimony_id, true);
        $criteria->compare('member_testimony_network_id', $this->member_testimony_network_id, true);
        $criteria->compare('sys_network.network_mid', $this->network_mid, true);
        $criteria->compare('member_testimony_content', $this->member_testimony_content, true);
        $criteria->compare('member_testimony_input_datetime', $this->member_testimony_input_datetime, true);
        $criteria->compare('member_testimony_is_approve', $this->member_testimony_is_approve, true);
        $criteria->compare('member_testimony_order_by', $this->member_testimony_order_by, true);
        $criteria->compare('member_testimony_home_is_active', $this->member_testimony_home_is_active, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

}